#include <stdio.h>      // 标准输入输出
#include "iot_pwm.h"
#include "hi_pwm.h"
#include "hi_io.h"
#include "ohos_init.h"
#include "iot_gpio.h"
#include "cmsis_os2.h"

static void Buzzer(void *arg){
    (void)arg;

    IoTGpioInit(HI_IO_NAME_GPIO_9);//初始化PWM
    hi_io_set_func(HI_IO_NAME_GPIO_9, HI_IO_FUNC_GPIO_9_PWM0_OUT);//IO复用为PWM功能
    IoTGpioSetDir(HI_IO_NAME_GPIO_9, IOT_GPIO_DIR_OUT);//设置为输出
    IoTPwmInit(HI_PWM_PORT_PWM0);//初始化PWM功能 端口号
    IoTPwmStart(HI_PWM_PORT_PWM0,  50,4000);//启动PWM功能, 端口，占空比，分频倍数
    osDelay(300); //响时3秒
    IoTPwmStop(HI_PWM_PORT_PWM0);//停止PWM
}

static void BuzEntry(void)
{
    osThreadAttr_t attr;
    attr.name="Buzzer";
    attr.stack_size=4096;
    attr.priority=osPriorityNormal;
    if(osThreadNew(Buzzer,NULL,&attr)==NULL)
    {
        printf("create task");
    }

}

SYS_RUN(BuzEntry);
